package com.chen.web;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @decription
 * @atuhor:陈红卫
 * @create : 2017-06-17-9:11
 */
@Service
public class HelloService {

    @Autowired
     private RestTemplate restTemplate;

    /*
    * groupKey设置命令的组名称，默认按照组名称划分线程池。但也可以通过threadPoolKey单独设置线程池
    * */
    @HystrixCommand(fallbackMethod = "helloFallback",groupKey = "123")
     public String  helloService(){
         return restTemplate.getForEntity("http://HELLO-SERVICE/hello",String.class).getBody();
    }


    /*
    * 服务降级的实现方法
    * */
    public String helloFallback(){
         return "error";
    }



}
